﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace MedievalGameProject
{
    public class PlayerController : Controller
    {
        KeyboardState prevKeyState;
        MouseState prevMouseState;

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();

            Vector3 direction = Game1.camera.cameraDirection;
            direction = new Vector3(direction.X, 0, direction.Z);

            if (keyboardState.IsKeyDown(Keys.W))
            {
                CurrentActor.Move(direction);
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                CurrentActor.Move(-direction);
            }
            if (keyboardState.IsKeyDown(Keys.A))
            {
                CurrentActor.Move(Game1.camera.GetStrafeDirection());
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                CurrentActor.Move(-Game1.camera.GetStrafeDirection());
            }
            if (keyboardState.IsKeyDown(Keys.Space))
            {
                CurrentActor.Jump();
            }

            if (prevMouseState.LeftButton != ButtonState.Pressed && 
                mouseState.LeftButton == ButtonState.Pressed)
            {
                CurrentActor.FireWeapon();
            }


            prevKeyState = keyboardState;
            prevMouseState = mouseState;
        }
    }
}
